Skip to content

London | 26-ITP-Sep | Hanna Bohlin | Sprint 2 | Practice TDD - #1720

Open
habohlin wants to merge 48 commits into
CodeYourFuture:mainfrom
habohlin:Practice-TDD
Open

habohlin wants to merge 48 commits into
CodeYourFuture:mainfrom
habohlin:Practice-TDD

Conversation

@habohlin

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1060

Changelist

Completed the three exercises in Practice TDD with one commit for each added test and one commit for each refactor.

@habohlin habohlin added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 16, 2026
@Liam310 Liam310 added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 20, 2026
Comment thread practice-tdd/count.js Outdated
Comment on lines +2 to +10
let numOfa = 0;

for (let i = 0; i < stringOfCharacters.length; i++) {
if (stringOfCharacters.charAt(i) === findCharacter) {
numOfa++;
}
}

return numOfa;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name numOfa is a little confusing. What does this variable represent exactly? I think you could find a better, more descriptive name.

Comment thread practice-tdd/get-ordinal-number.js Outdated
Comment on lines +6 to +24
if ((num - 11) % 100 === 0) {
return num + "th";
}

if ((num - 1) % 10 === 0) {
return num + "st";
}

if ((num - 12) % 100 === 0) {
return num + "th";
}

if ((num - 2) % 10 === 0) {
return num + "nd";
}

if ((num - 13) % 100 === 0) {
return num + "th";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several of these if statements have the same body:

return num + "th";

How can you take advantage of this to make the function a bit shorter and easier to read?

Comment on lines +21 to +27

// Case 2: Numbers ending with 11. Should append "th" to the number
test("should append 'th' for numbers ending with 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(4211)).toEqual("4211th");
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great separation of behaviours for this test suite! 👌

Comment thread practice-tdd/get-ordinal-number.test.js Outdated
Comment on lines +65 to +80
test("should throw error for all invalid numbers", () => {
expect(() => {
getOrdinalNumber(5.7);
}).toThrow("Error: whole number is needed");
expect(() => {
getOrdinalNumber();
}).toThrow("Error: whole number is needed");
expect(() => {
getOrdinalNumber("hey");
}).toThrow("Error: whole number is needed");
expect(() => {
getOrdinalNumber(undefined);
}).toThrow("Error: whole number is needed");
expect(() => {
getOrdinalNumber(null);
}).toThrow("Error: whole number is needed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll always prefer too many test over not enough, but this is probably too many. Additionally, I think the test description is a little confusing. It says "should throw error for all invalid numbers" - but almost all of these are not numbers.

I think there's probably two different tests here:

  1. Test for actually invalid numbers
  2. Test for... what do you think?

Comment thread practice-tdd/repeat-str.test.js Outdated
// Then it should return a string that contains the original `str` repeated `count` times.

test("should repeat the string count times", () => {
test("should repeat the string count times, count is 3", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to your last PR, test descriptions aren't there to tell us exactly what the input value is - we can look in the body of the test to see that. Here, "should repeat the string count times" is a generic description of the behaviour that is being tested by the function, so it is a good description on its own. Whether it's 3, 4, or 5 - the point is that the function can repeat a string multiple times.

If you want multiple assertions for the same behaviour that's fine - they ought to be part of the same test

@Liam310 Liam310 added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Oct 23, 2026
@Liam310

Liam310 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@habohlin Hey Hanna, good work on this one, just a few small notes from me.

Also, I am about to go away on annual leave - I'll keep this tab open so I can return to look at your work when I come back, but if there's an urgent need to have a follow-up review, feel free to ask another member of staff and explain the situation 🙂

@habohlin habohlin added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants